<!DOCTYPE html>
<!-- saved from url=(0097)http://people.csail.mit.edu/dnj/teaching/6170/accelerator/modules/objects/code/reaction-funs.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../editor/codestyles.css">
    <script src="../editor/codeeditor.js"></script>
	

    <style>
    canvas {position: absolute; left: 580px; top: 67px}
    </style>    
</head>
<body style="">

<div id="buttons">
	<input type="submit" value="run" id="runIntro" onclick="slide.runCode();">
	<input type="submit" value="clear output" id="clearOutput" onclick="clearOutputBox();">
	<input type="submit" value="revert" id="reloadCode" onclick="location.reload();">
</div>

<canvas id="canvas" height="200" width="200"></canvas>

<script>
//return time in ms
var now = function () {return new Date().getTime();}
var avg = function (a) {
    var result = 0;
    a.forEach(function (e) {
        result += e;
    });
    return Math.floor(result / a.length);
	}

Array.prototype.zip = function (a, f) {
	var result = [];
	for (i=0; i < this.length; i++)
		result.push(f(this[i], a[i]))
	return result;
	}

var pos = function (x) {return x >= 0;}

var plus = function (a, b) {return a + b;}

var not = function (f) {return function (x) {return !f(x)}};
//  console.log("avg([1,3,5]) is " + avg([1,3,5]));
//   console.log("Average time is " + (2*avg(events)) + "ms");

// not sure why but can't seem to pass Math.max to reduce
var max = function (a, b) {return Math.max(a, b);}

</script>

<textarea id="code" name="code" style="display: none;"> console.log("pos(3) is " + pos(3));
 console.log("pos(-3) is " + pos(-3));
 console.log("not(pos)(3) is " + (not(pos))(3));
 console.log("max(3,4) is " + max(3,4));
 console.log("[1,2,3].zip ([4,5,6], plus) is [" + [1,2,3].zip ([4,5,6], plus) + "]");</textarea><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 8.99306px; left: 49.9884px;"><textarea style="position: absolute; padding: 0; width: 1px; height: 1em" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default" tabindex="-1"><div style="position: relative; height: 123.4px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-gutter" style="height: 124px;"><div class="CodeMirror-gutter-text"><pre>1</pre><pre>2</pre><pre>3</pre><pre>4</pre><pre>5</pre></div></div><div class="CodeMirror-lines"><div style="position: relative; z-index: 0; outline: none; margin-left: 41px;"><div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden; outline: 5px auto none"></div><pre class="CodeMirror-cursor" style="top: 0px; left: 0px;">&nbsp;</pre><div style="position: relative; z-index: -1; display: none;"></div><div style=""><pre><span class="cm-variable"> console.log</span>(<span class="cm-string">"pos(3) is "</span> + <span class="cm-variable">pos</span>(<span class="cm-number">3</span>));</pre><pre><span class="cm-variable"> console.log</span>(<span class="cm-string">"pos(-3) is "</span> + <span class="cm-variable">pos</span>(-<span class="cm-number">3</span>));</pre><pre><span class="cm-variable"> console.log</span>(<span class="cm-string">"not(pos)(3) is "</span> + (<span class="cm-variable">not</span>(<span class="cm-variable">pos</span>))(<span class="cm-number">3</span>));</pre><pre><span class="cm-variable"> console.log</span>(<span class="cm-string">"max(3,4) is "</span> + <span class="cm-variable">max</span>(<span class="cm-number">3</span>,<span class="cm-number">4</span>));</pre><pre><span class="cm-variable"> console.log</span>(<span class="cm-string">"[1,2,3].zip ([4,5,6], plus) is ["</span> + [<span class="cm-number">1</span>,<span class="cm-number">2</span>,<span class="cm-number">3</span>].<span class="cm-property">zip</span> ([<span class="cm-number">4</span>,<span class="cm-number">5</span>,<span class="cm-number">6</span>], <span class="cm-variable">plus</span>) + <span class="cm-string">"]"</span>);</pre></div></div></div></div></div></div></div>
<div id="output"><i>Output</i></div>



</body></html>